﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BDH.DAL
{
    using BDH.DAL.Entities;
    public class DuongDAL : BaseDAL, BDH.UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT d.id,d.ma,tenduong,p.tenphuong FROM Duong d JOIN Phuong p ON d.phuong_id = p.id ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(int id)
        {
            string sql = @" SELECT id,ma,tenduong FROM Duong WHERE phuong_id = '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id1, string id2)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            string sql = @" DELETE FROM Duong WHERE id = {0} ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Duong)obj;
            string sql = @" INSERT INTO Duong(ma,tenduong,phuong_id) VALUES('{0}', N'{1}', '{2}') ";
            sql = string.Format(sql, o.ma, o.tenduong, o.phuong_id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Duong)obj;
            string sql = @" UPDATE Duong SET tenduong = N'{0}' WHERE id = {1} ";
            sql = string.Format(sql, o.tenduong, o.id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }
    }
}
